﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellEndpoint_h
#define CellEndpoint_h

#include "CellPrerequisites.h"
#include "CellNucleus.h"
#include "CellInet4Address.h"
#include "CellInet6Address.h"

namespace cell
{

/** 云图中的节点。
每一个顶点都是一个可独立运作的逻辑单元，例如一个独立的服务消费者或者一组服务生产者。
	
@author
	Jiangwei Xu
*/
class _CellExport Endpoint : public GeneralAlloc
{
public:
	/** 构造函数。
	*/
	Endpoint(const NucleusTag& tag, NucleusConfig::Role role, const InetAddress& address, int hop);

	/** 构造函数。
	*/
	Endpoint(const String& tag, NucleusConfig::Role role, const InetAddress& address, int hop);

protected:
	///
	Endpoint(const Endpoint& other);

public:
	/** 析构函数。
	*/
	virtual ~Endpoint(void);

	/** 节点坐标描述。
	*/
	class _CellExport Coordinate : public GeneralAlloc
	{
	public:
		/**
		*/
		Coordinate(void);
		/**
		*/
		virtual ~Coordinate(void);

	public:
		/**
		*/
		const Inet4Address& getV4Address(void) const;

		/**
		*/
		const Inet6Address& getV6Address(void) const;

	protected:
		/**
		*/
		void setV4Address(const Inet4Address& address);

		/**
		*/
		void setV6Address(const Inet6Address& address);

	private:
		Inet4Address mV4Address;
		Inet6Address mV6Address;

		friend class Endpoint;
	};

public:
	/**
	*/
	const NucleusTag& getTag(void) const;

	/**
	*/
	const NucleusConfig::Role getRole(void) const;

	/**
	*/
	const Coordinate& getCoordinate(void) const;

	/**
	*/
	void addCelletIdentity(const String& identity);

	/**
	*/
	void removeCelletIdentity(const String& identity);

protected:
	/**
	*/
	void setAddress(const InetAddress& address);

private:
	NucleusTag mNucleusTag;
	NucleusConfig::Role mRole;
	Coordinate mCoordinate;

	///!< 跳数
	int mHop;
};

} // end namespace cell

#endif // CellEndpoint_h
